package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bean.acgBeanVo.BaseData;
import com.kuang.demo.bean.lhf.Topic;
import com.kuang.demo.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    TopicService topicService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String sort,
                           String order, String title, String subtitle){
        //获取所需数据
        BaseData data = topicService.queryTopicList(page, limit, sort, order,title,subtitle);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Topic topic){
        topicService.updateTopic(topic);
        return BaseRespVo.ok(topic);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Topic topic){
        topicService.deleteTopic(topic);
        return BaseRespVo.ok();
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Topic topic){
        Topic createTopic = topicService.createTopic(topic);
        return BaseRespVo.ok(createTopic);
    }
}
